package com.qf.bookshop2.controller;

import com.qf.bookshop2.model.Book;
import com.qf.bookshop2.model.User;
import com.qf.bookshop2.service.IBuyBookService;
import com.qf.bookshop2.service.impl.BuyBookServiceImpl;
import com.qf.bookshop2.util.ExchangeMoneyOrNumException;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;

import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
//@RequestMapping("/sell")
public class SellBooksController {

    //加载事务
    @Autowired
    IBuyBookService service;



    @RequestMapping("/buyBooks")
    public String buyBooks(Integer id, Integer bid, Integer bnum, HttpSession session){
        try {
            String username = (String) session.getAttribute("username");
            service.buyBooks(username,bid,bnum);
        }catch (ExchangeMoneyOrNumException e){
            return "fail";
        }
        return "redirect:index";
    }


}
